<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title th:text="${'承接详情 - ' + taskApplication.applicationId}">承接详情</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div th:replace="~{fragments/header :: header}"></div>
    
    <div class="container mt-4">
        <h2>任务承接详情</h2>
        
        <div class="card">
            <div class="card-body">
                <h5 class="card-title">承接信息</h5>
                <ul class="list-group list-group-flush">
                    <li class="list-group-item">
                        <strong>承接编号:</strong> 
                        <span th:text="${taskApplication.applicationId}">承接编号</span>
                    </li>
                    <li class="list-group-item">
                        <strong>任务编号:</strong> 
                        <span th:text="${taskApplication.taskId}">任务编号</span>
                    </li>
                    <li class="list-group-item">
                        <strong>承接时间:</strong> 
                        <span th:text="${#temporals.format(taskApplication.applyTime, 'yyyy-MM-dd HH:mm')}">承接时间</span>
                    </li>
                    <li class="list-group-item">
                        <strong>交付时间:</strong> 
                        <span th:text="${#temporals.format(taskApplication.deliveryTime, 'yyyy-MM-dd HH:mm')}">交付时间</span>
                    </li>
                    <li class="list-group-item">
                        <strong>交付状态:</strong>
                        <span th:if="${taskApplication.deliveryStatus == 'not_delivered'}" class="badge bg-primary">未交付</span>
                        <span th:if="${taskApplication.deliveryStatus == 'delivered'}" class="badge bg-warning">已交付</span>
                        <span th:if="${taskApplication.deliveryStatus == 'confirmed'}" class="badge bg-success">已确认</span>
                    </li>
                    <li class="list-group-item">
                        <strong>创建时间:</strong> 
                        <span th:text="${#temporals.format(taskApplication.createTime, 'yyyy-MM-dd HH:mm')}">创建时间</span>
                    </li>
                    <li class="list-group-item">
                        <strong>更新时间:</strong> 
                        <span th:text="${#temporals.format(taskApplication.updateTime, 'yyyy-MM-dd HH:mm')}">更新时间</span>
                    </li>
                </ul>
            </div>
        </div>
        
        <!-- 附件列表 -->
        <div class="card mt-4" th:if="${attachments != null and not #lists.isEmpty(attachments)}">
            <div class="card-body">
                <h5 class="card-title">交付附件</h5>
                <div class="table-responsive">
                    <table class="table">
                        <thead>
                            <tr>
                                <th>文件名</th>
                                <th>文件大小</th>
                                <th>上传时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr th:each="attachment : ${attachments}" th:if="${attachment != null}">
                                <td th:text="${attachment.fileName}">文件名</td>
                                <td th:text="${#numbers.formatDecimal(attachment.fileSize / 1024.0, 1, 2) + ' KB'}">文件大小</td>
                                <td th:text="${#temporals.format(attachment.uploadTime, 'yyyy-MM-dd HH:mm')}">上传时间</td>
                                <td>
                                    <a th:href="@{/freelancer/task-applications/attachment/{id}(id=${attachment.attachmentId})}" class="btn btn-sm btn-primary">下载</a>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        
        <!-- 交付表单 -->
        <div class="card mt-4" th:if="${taskApplication.deliveryStatus == 'not_delivered'}">
            <div class="card-body">
                <h5 class="card-title">提交成果物</h5>
                <form th:action="@{/freelancer/task-applications/{applicationId}/submit-delivery(applicationId=${taskApplication.applicationId})}" 
                      method="post" 
                      enctype="multipart/form-data">
                    <div class="mb-3">
                        <label for="attachments" class="form-label">上传附件</label>
                        <input type="file" class="form-control" id="attachments" name="attachments" multiple>
                        <div class="form-text">可以选择多个文件</div>
                    </div>
                    <button type="submit" class="btn btn-success"
                            onclick="return confirm('确定要提交成果物吗？')">提交成果物</button>
                </form>
            </div>
        </div>
        
        <div class="mt-3">
            <a th:href="@{/freelancer/task-applications}" class="btn btn-secondary">返回列表</a>
            <form th:action="@{/freelancer/task-applications/{id}/retract(id=${taskApplication.applicationId})}" method="post" style="display: inline;" th:if="${taskApplication.deliveryStatus == 'delivered'}">
                <button type="submit" class="btn btn-warning"
                        onclick="return confirm('确定要撤回交付吗？')">撤回交付</button>
            </form>
        </div>
    </div>
    
    <div th:replace="~{fragments/footer :: footer}"></div>
</body>
</html>